package com.voquanghoa.com.sudokumaster.controllers;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

import com.voquanghoa.com.sudokumaster.adapters.SudokuCellAdapter;

/**
 * Created by Vo Quang Hoa on 12/30/2014.
 */
public class SudokuGridView extends GridView {

	private Context mContext;
	public SudokuGridView(Context context) {
		super(context);
		InitView(context);
	}
	public SudokuGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
		InitView(context);
	}

	public SudokuGridView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		InitView(context);
	}

	private void InitView(Context context){
		mContext = context;
		this.setAdapter(new SudokuCellAdapter(mContext));
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		SudokuCellAdapter.SudokuCellWidth = MeasureSpec.getSize(widthMeasureSpec)/9;
		SudokuCellAdapter.SudokuCellHeight = MeasureSpec.getSize(heightMeasureSpec)/9;

		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {

		super.onSizeChanged(w, h, oldw, oldh);
		SudokuCellAdapter.SudokuCellHeight = h/9;
		SudokuCellAdapter.SudokuCellWidth = w/9;
		((SudokuCellAdapter)this.getAdapter()).updateCellsSize();
	}
}
